class AnswerBlob < ActiveRecord::Base
  belongs_to :assignment_answer

  validates_presence_of :data, :message => 'La respuesta no puede estar vacía.'

  def data=(param)
    if param.is_a?(StringIO) or param.is_a?(Tempfile)
      self[:file_name] = param.original_filename.gsub(/^.*(\\|\/)/, '')
      self[:data] = param.read
    else
      self[:data] = param
    end
  end
end
